package b2.widget.social
{
	import b2.net.*;
	import b2.util.*;
	import b2.player.*;
	import b2.widget.*;
	import b2.widget.friend.*;
	
	import com.greensock.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;
	import flash.ui.*;
	
	public class SocialMessageBox extends Sprite
	{
		private var alice:Sprite;
		private var contentIndex:int;
		private var contentText:TextField;
		
		public function SocialMessageBox()
		{
			//对话框背景
			var DialogBgr:Class = ResourceHelper.getInstance().getClassByName("GuideMessageBgr");
			addChild(new DialogBgr());
			//对话
			contentText = new TextField();
			contentText.selectable = false;
        	contentText.autoSize = TextFieldAutoSize.LEFT;
        	contentText.multiline = true;
        	var contentFormat:TextFormat = new TextFormat("微软雅黑", 16, 0x000000, true);
        	contentFormat.letterSpacing = 1;
        	contentFormat.leading = 10;
			contentText.defaultTextFormat = contentFormat;
			contentText.wordWrap = true;
			contentText.width = 250;
			contentText.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			contentText.x = 40;
			contentText.y = 25;
			addChild(contentText);
			contentIndex = 0;
			showContent(0);
			//报复
			var ButtonFire:Class = ResourceHelper.getInstance().getClassByName("ButtonFire");
			var revengeButton:BasicButton = new BasicButton(ButtonFire, "<b><font color='#FF0000'>向 ta 复仇</font></b>");
			revengeButton.x = 195;
			revengeButton.y = 96;
			addChild(revengeButton);
			revengeButton.addEventListener(MouseEvent.CLICK, onMouseClick);
			//参谋美女
			var Alice:Class = ResourceHelper.getInstance().getClassByName("Alice");
			alice = new Alice();
			alice.height = 350;
			alice.scaleX = alice.scaleY;
			alice.x = -80;
			alice.y = -100;
			addChild(alice);
			var ButtonBgr:Class = ResourceHelper.getInstance().getClassByName("ButtonBgr0");
			//确定按钮
			var buttonClose:BasicButton = new BasicButton(ButtonBgr, "关闭");
			buttonClose.addEventListener(MouseEvent.CLICK, onButtonCloseClick);
			buttonClose.x = 90;
			buttonClose.y = 150;
			addChild(buttonClose);
			//确定按钮
			var buttonOK:BasicButton = new BasicButton(ButtonBgr, "下一条");
			buttonOK.addEventListener(MouseEvent.CLICK, onButtonOKClick);
			buttonOK.x = 200;
			buttonOK.y = 150;
			addChild(buttonOK);
		}
		
		private function onMouseClick(event:MouseEvent):void
		{
			var me:PlayerInfo = PlayerInfoManager.getInstance().me;
			var socialInfo:SocialInfo = me.socialPackage.socialList[contentIndex];
			ServerHelper.getInstance().getPlayerInfo(socialInfo.attackerId);
			ServerHelper.getInstance().addEventListener(ServerEvent.GET_PLAYER_INFO, onShowTankInfoComplete);
		}
		
		private function onShowTankInfoComplete(event:ServerEvent):void
		{
			var me:PlayerInfo = PlayerInfoManager.getInstance().me;
			var socialInfo:SocialInfo = me.socialPackage.socialList[contentIndex];
			ServerHelper.getInstance().removeEventListener(ServerEvent.GET_PLAYER_INFO, onShowTankInfoComplete);
			var friendDialog:FriendDialog = new FriendDialog(1, socialInfo.attackerId);
			WidgetManager.getInstance().popOut([friendDialog], true, true);
		}
		
		private function onButtonCloseClick(event:MouseEvent):void
		{
			close();
		}
		
		private function onButtonOKClick(event:MouseEvent):void
		{
			var me:PlayerInfo = PlayerInfoManager.getInstance().me;
			if (contentIndex < me.socialPackage.socialList.length - 1)
			{
				showContent(++contentIndex);
			}
			else
			{
				close();
			}	
		}
		
		private function showContent(contentIndex:int):void
		{
			var me:PlayerInfo = PlayerInfoManager.getInstance().me;
			var socialInfo:SocialInfo = me.socialPackage.socialList[contentIndex];
			contentText.htmlText = "<font color='#0000FF'>" + socialInfo.attackerName + "</font> 在 <font color='#0000FF'>" + 
			socialInfo.attackDate.substr(5, 11) + "</font> 攻击你的要塞，抢走荣誉 <font color='#00AA00'>" + socialInfo.honourChange + "</font>";
			contentText.alpha = 1;
			TweenLite.from(contentText, 2, {alpha: 0});
		}
		
		public function close():void
		{
			if (this.parent != null)
			{
				this.parent.removeChild(this);
			}
		}
		
	}
}